//
//  BDNetworkingServer.m
//  BadBoy
//
//  Created by 余勇 on 2017/3/8.
//  Copyright © 2017年 niusaibing. All rights reserved.
//

#import "BDNetworkingServer.h"
#import "AFNetworking.h"
#import "BDUserModel.h"

@interface BDNetworkingServer ()

+ (AFHTTPSessionManager *)customManagerWithValidation:(NSString *)validation;

@end

@implementation BDNetworkingServer

+ (NSInteger)getErrorCodeWithError:(NSError *)error{
    NSData *jsonData = error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey];
    if (jsonData != nil) {
        NSString *status_code = [self parseJSONStringToNSDictionary:jsonData];
        return status_code.integerValue;
    }
    // BDLog(ASLocalizedString(@"当前error没有返回的错误码，查看原来的错误码是：%@"), @(error.code));
    return error.code;
}

+ (NSString *)parseJSONStringToNSDictionary:(NSData *)JSONData{
    //    NSData *JSONData = [JSONString dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *responseJSON = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingMutableLeaves error:nil];
    NSString *status_code = [responseJSON objectForKey:@"status_code"];
    
    return status_code;
}

+ (AFHTTPSessionManager *)v2CustomManagerWithValidation:(NSString *)validation{
    AFHTTPSessionManager *manager =[AFHTTPSessionManager manager];
    //    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    //    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    [manager.requestSerializer setValue:@"application/x.beboy.v2+json" forHTTPHeaderField:@"Accept"];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",
                                                         @"text/html",
                                                         @"image/jpeg",
                                                         @"image/png",
                                                         @"application/octet-stream",
                                                         @"text/json",
                                                         nil];
    
    [manager.requestSerializer setValue:@"application/x-www-form-urlencoded; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
    //设置头部验证
    if (validation != nil) {
        [manager.requestSerializer setValue:validation forHTTPHeaderField:@"Authorization"];
    }
    return manager;
}

+ (AFHTTPSessionManager *)customManagerWithValidation:(NSString *)validation{
    AFHTTPSessionManager *manager =[AFHTTPSessionManager manager];
//    manager.requestSerializer = [AFJSONRequestSerializer serializer];
//    manager.responseSerializer = [AFJSONResponseSerializer serializer];
//    [manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Accept"];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",
//                                                         @"text/html",
                                                         @"image/jpeg",
                                                         @"image/png",
                                                         @"application/octet-stream",
                                                         @"text/json",
                                                         nil];
    
    [manager.requestSerializer setValue:@"application/x-www-form-urlencoded; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
    //设置头部验证
    if (validation != nil) {
        [manager.requestSerializer setValue:validation forHTTPHeaderField:@"Authorization"];
    }
    return manager;
}

+ (RACCommand *)v2_GET:(NSString *)url parameters:(id)parameters validation:(NSString *)validation automaticProcessingError:(BOOL)automaticProcessingError{
    return [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            AFHTTPSessionManager *manager =[self v2CustomManagerWithValidation:validation];
            [manager GET:url parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                NSInteger statusCode = [responseObject[@"status_code"] integerValue];
                if (statusCode == 200) {
                    [subscriber sendNext:responseObject[@"data"]];
                    [subscriber sendCompleted];
                }else{
                    NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:statusCode userInfo:nil];
                    [subscriber sendError:error];
                }
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                NSInteger faildCode = [self getErrorCodeWithError:error];
                NSError *newError = [NSError errorWithDomain:NSCocoaErrorDomain code:faildCode userInfo:nil];
                if (automaticProcessingError == YES) {
                    [self errorHandlingWithErrrCode:faildCode url:url];
                }
                [subscriber sendError:newError];
            }];
            return nil;
        }];
    }];
}

+ (RACCommand *)yy_GET:(NSString *)url parameters:(id)parameters validation:(NSString *)validation automaticProcessingError:(BOOL)automaticProcessingError{
    return [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            AFHTTPSessionManager *manager =[self customManagerWithValidation:validation];
            [manager GET:url parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                NSInteger statusCode = [responseObject[@"status_code"] integerValue];
                if (statusCode == 200) {
                    [subscriber sendNext:responseObject[@"data"]];
                    [subscriber sendCompleted];
                }else{
                    NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:statusCode userInfo:nil];
                    [subscriber sendError:error];
                }
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                NSInteger faildCode = [self getErrorCodeWithError:error];
                NSError *newError = [NSError errorWithDomain:NSCocoaErrorDomain code:faildCode userInfo:nil];
                if (automaticProcessingError == YES) {
                    [self errorHandlingWithErrrCode:faildCode url:url];
                }
                [subscriber sendError:newError];
            }];
            return nil;
        }];
    }];
}

+ (RACCommand *)yy_POST:(NSString *)url parameters:(id)parameters validation:(NSString *)validation automaticProcessingError:(BOOL)automaticProcessingError{
    return [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            AFHTTPSessionManager *manager =[self customManagerWithValidation:validation];
            [manager POST:url parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                NSInteger statusCode = [responseObject[@"status_code"] integerValue];
                if (statusCode == 200) {
                    [subscriber sendNext:responseObject[@"data"]];
                    [subscriber sendCompleted];
                }else{
                    NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:statusCode userInfo:nil];
                    [subscriber sendError:error];
                }
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                NSInteger faildCode = [self getErrorCodeWithError:error];
                NSError *newError = [NSError errorWithDomain:NSCocoaErrorDomain code:faildCode userInfo:nil];
                if (automaticProcessingError == YES) {
                    [self errorHandlingWithErrrCode:faildCode url:url];
                }
                [subscriber sendError:newError];
            }];
            return nil;
        }];
    }];
}

+ (RACCommand *)yy_POST:(NSString *)URLString parameters:(id)parameters validation:(NSString *)validation name:(NSString *)name dataArray:(NSArray *)dataArray automaticProcessingError:(BOOL)automaticProcessingError{
    return [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            AFHTTPSessionManager *manager =[self customManagerWithValidation:validation];
            [manager POST:URLString parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
                //上传的参数(上传图片，以文件流的格式)
                // 在网络开发中，上传文件时，是文件不允许被覆盖，文件重名
                // 要解决此问题，
                // 可以在上传时使用当前的系统事件作为文件名
                
                NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
                // 设置时间格式
                formatter.dateFormat = @"yyyyMMddHHmmss";
                NSString *str = [formatter stringFromDate:[NSDate date]];
                for (int i = 0; i < dataArray.count; i++) {
                    NSString *fileName = [NSString stringWithFormat:@"%@_%d.jpg", str, i];
                    [formData appendPartWithFileData:dataArray[i] name:name fileName:fileName mimeType:@"image/jpg/png/jpeg"];
                }
//                NSString *filePath = [CachePaths stringByAppendingPathComponent:fileName];
//                [formData appendPartWithFileURL:[NSURL fileURLWithPath:filePath] name:key error:nil];
            } progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                NSInteger statusCode = [responseObject[@"status_code"] integerValue];
                if (statusCode == 200) {
                    [subscriber sendNext:responseObject[@"data"]];
                    [subscriber sendCompleted];
                }else{
                    NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:statusCode userInfo:nil];
                    [subscriber sendError:error];
                }
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                NSInteger faildCode = [self getErrorCodeWithError:error];
                NSError *newError = [NSError errorWithDomain:NSCocoaErrorDomain code:faildCode userInfo:nil];
                if (automaticProcessingError == YES) {
                    [self errorHandlingWithErrrCode:faildCode url:URLString];
                }
                [subscriber sendError:newError];
            }];
            return nil;
        }];
    }];
}

+ (nullable RACCommand *)v2_POST:(nullable NSString *)URLString
                      parameters:(nullable id)parameters
                      validation:(nullable NSString *)validation
                       nameArray:(nullable NSArray *)nameArray
                       dataArray:(nullable NSArray *)dataArray
        automaticProcessingError:(BOOL)automaticProcessingError{
    return [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            AFHTTPSessionManager *manager =[self v2CustomManagerWithValidation:validation];
            [manager POST:URLString parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
                //上传的参数(上传图片，以文件流的格式)
                // 在网络开发中，上传文件时，是文件不允许被覆盖，文件重名
                // 要解决此问题，
                // 可以在上传时使用当前的系统事件作为文件名
                
                NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
                // 设置时间格式
                formatter.dateFormat = @"yyyyMMddHHmmss";
                NSString *str = [formatter stringFromDate:[NSDate date]];
                for (int i = 0; i < nameArray.count; i++) {
                    NSString *name = nameArray[i];
                    id dataObject = dataArray[i];
                    if ([dataObject isKindOfClass:[NSArray class]]) {
                        NSArray *newDaArr = dataObject;
                        for (int j = 0; j < newDaArr.count; j++) {
                            NSString *fileName = [NSString stringWithFormat:@"%@_%d_%d.jpg", str, j, i];
                            [formData appendPartWithFileData:newDaArr[j] name:name fileName:fileName mimeType:@"image/jpeg"];
                        }
                    }else{
                        NSString *fileName = [NSString stringWithFormat:@"%@_%d.jpg", str, i];
                        [formData appendPartWithFileData:dataObject name:name fileName:fileName mimeType:@"image/jpeg"];
                    }
                }
                //                for (int i = 0; i < dataArray.count; i++) {
                //                    NSString *fileName = [NSString stringWithFormat:@"%@_%d.jpg", str, i];
                //                    [formData appendPartWithFileData:dataArray[i] name:name fileName:fileName mimeType:@"image/jpeg"];
                //                }
                //                NSString *filePath = [CachePaths stringByAppendingPathComponent:fileName];
                //                [formData appendPartWithFileURL:[NSURL fileURLWithPath:filePath] name:key error:nil];
            } progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                NSInteger statusCode = [responseObject[@"status_code"] integerValue];
                if (statusCode == 200) {
                    [subscriber sendNext:responseObject[@"data"]];
                    [subscriber sendCompleted];
                }else{
                    NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:statusCode userInfo:nil];
                    [subscriber sendError:error];
                }
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                NSInteger faildCode = [self getErrorCodeWithError:error];
                NSError *newError = [NSError errorWithDomain:NSCocoaErrorDomain code:faildCode userInfo:nil];
                if (automaticProcessingError == YES) {
                    [self errorHandlingWithErrrCode:faildCode url:URLString];
                }
                [subscriber sendError:newError];
            }];
            return nil;
        }];
    }];
}

+ (nullable RACCommand *)yy_POST:(nullable NSString *)URLString
                      parameters:(nullable id)parameters
                      validation:(nullable NSString *)validation
                       nameArray:(nullable NSArray *)nameArray
                       dataArray:(nullable NSArray *)dataArray
        automaticProcessingError:(BOOL)automaticProcessingError{
    return [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            AFHTTPSessionManager *manager =[self customManagerWithValidation:validation];
            [manager POST:URLString parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
                //上传的参数(上传图片，以文件流的格式)
                // 在网络开发中，上传文件时，是文件不允许被覆盖，文件重名
                // 要解决此问题，
                // 可以在上传时使用当前的系统事件作为文件名
                
                NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
                // 设置时间格式
                formatter.dateFormat = @"yyyyMMddHHmmss";
                NSString *str = [formatter stringFromDate:[NSDate date]];
                for (int i = 0; i < nameArray.count; i++) {
                    NSString *name = nameArray[i];
                    id dataObject = dataArray[i];
                    if ([dataObject isKindOfClass:[NSArray class]]) {
                        NSArray *newDaArr = dataObject;
                        for (int j = 0; j < newDaArr.count; j++) {
                            NSString *fileName = [NSString stringWithFormat:@"%@_%d_%d.jpg", str, j, i];
                            [formData appendPartWithFileData:newDaArr[i] name:name fileName:fileName mimeType:@"image/jpeg"];
                        }
                    }else{
                        NSString *fileName = [NSString stringWithFormat:@"%@_%d.jpg", str, i];
                        [formData appendPartWithFileData:dataObject name:name fileName:fileName mimeType:@"image/jpeg"];
                    }
                }
//                for (int i = 0; i < dataArray.count; i++) {
//                    NSString *fileName = [NSString stringWithFormat:@"%@_%d.jpg", str, i];
//                    [formData appendPartWithFileData:dataArray[i] name:name fileName:fileName mimeType:@"image/jpeg"];
//                }
                //                NSString *filePath = [CachePaths stringByAppendingPathComponent:fileName];
                //                [formData appendPartWithFileURL:[NSURL fileURLWithPath:filePath] name:key error:nil];
            } progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                NSInteger statusCode = [responseObject[@"status_code"] integerValue];
                if (statusCode == 200) {
                    [subscriber sendNext:responseObject[@"data"]];
                    [subscriber sendCompleted];
                }else{
                    NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:statusCode userInfo:nil];
                    [subscriber sendError:error];
                }
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                NSInteger faildCode = [self getErrorCodeWithError:error];
                NSError *newError = [NSError errorWithDomain:NSCocoaErrorDomain code:faildCode userInfo:nil];
                if (automaticProcessingError == YES) {
                    [self errorHandlingWithErrrCode:faildCode url:URLString];
                }
                [subscriber sendError:newError];
            }];
            return nil;
        }];
    }];
}

+ (RACCommand *)yy_Application_PUT:(NSString *)url parameters:(id)parameters validation:(NSString *)validation automaticProcessingError:(BOOL)automaticProcessingError{
    return [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            
            NSMutableURLRequest* formRequest = [[AFHTTPRequestSerializer serializer] requestWithMethod:@"POST" URLString:url parameters:parameters error:nil];
//            requestWithMethod:@"POST" URLString:url parameters:parameters formerror:nil
            [formRequest setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
            
            AFHTTPSessionManager*manager = [AFHTTPSessionManager manager];
            
            AFJSONResponseSerializer* responseSerializer = [AFJSONResponseSerializer serializer];
            
            [responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"application/json",@"text/json",@"text/javascript",@"text/html",@"text/plain",nil]];
            
            manager.responseSerializer= responseSerializer;
            
            NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:formRequest uploadProgress:nil downloadProgress:nil completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
                if(error) {
                    
                    NSInteger faildCode = [self getErrorCodeWithError:error];
                    NSError *newError = [NSError errorWithDomain:NSCocoaErrorDomain code:faildCode userInfo:nil];
                    if (automaticProcessingError == YES) {
                        [self errorHandlingWithErrrCode:faildCode url:url];
                    }
                    [subscriber sendError:newError];
                    return;
                    
                    NSInteger statusCode = [responseObject[@"status_code"] integerValue];
                    if (statusCode == 200) {
                        [subscriber sendNext:responseObject[@"data"]];
                        [subscriber sendCompleted];
                    }else{
                        NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:statusCode userInfo:nil];
                        [subscriber sendError:error];
                    }
                    
                }
                
            }];
            
            
            [dataTask resume];
            
            
            
//            AFHTTPSessionManager *manager =[self customManagerWithValidation:validation];
//            [manager PUT:url parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//                NSInteger statusCode = [responseObject[@"status_code"] integerValue];
//                if (statusCode == 200) {
//                    [subscriber sendNext:responseObject[@"data"]];
//                    [subscriber sendCompleted];
//                }else{
//                    NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:statusCode userInfo:nil];
//                    [subscriber sendError:error];
//                }
//            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//                NSInteger faildCode = [self getErrorCodeWithError:error];
//                NSError *newError = [NSError errorWithDomain:NSCocoaErrorDomain code:faildCode userInfo:nil];
//                if (automaticProcessingError == YES) {
//                    [self errorHandlingWithErrrCode:faildCode];
//                }
//                [subscriber sendError:newError];
//            }];
            return nil;
        }];
    }];
}

+ (RACCommand *)yy_PUT:(NSString *)url parameters:(id)parameters validation:(NSString *)validation automaticProcessingError:(BOOL)automaticProcessingError{
    return [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            AFHTTPSessionManager *manager =[self customManagerWithValidation:validation];
            [manager PUT:url parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                NSInteger statusCode = [responseObject[@"status_code"] integerValue];
                if (statusCode == 200) {
                    [subscriber sendNext:responseObject[@"data"]];
                    [subscriber sendCompleted];
                }else{
                    NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:statusCode userInfo:nil];
                    [subscriber sendError:error];
                }
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                NSInteger faildCode = [self getErrorCodeWithError:error];
                NSError *newError = [NSError errorWithDomain:NSCocoaErrorDomain code:faildCode userInfo:nil];
                if (automaticProcessingError == YES) {
                    [self errorHandlingWithErrrCode:faildCode url:url];
                }
                [subscriber sendError:newError];
            }];
            return nil;
        }];
    }];
}

+ (nonnull RACCommand *)yy_DELETE:(nonnull NSString *)url
                       parameters:(nullable id)parameters
                       validation:(nullable NSString *)validation
         automaticProcessingError:(BOOL)automaticProcessingError{
    return [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            AFHTTPSessionManager *manager =[self customManagerWithValidation:validation];
            [manager DELETE:url parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                NSInteger statusCode = [responseObject[@"status_code"] integerValue];
                if (statusCode == 200) {
                    [subscriber sendNext:responseObject[@"data"]];
                    [subscriber sendCompleted];
                }else{
                    NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:statusCode userInfo:nil];
                    [subscriber sendError:error];
                }
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                NSInteger faildCode = [self getErrorCodeWithError:error];
                NSError *newError = [NSError errorWithDomain:NSCocoaErrorDomain code:faildCode userInfo:nil];
                if (automaticProcessingError == YES) {
                    [self errorHandlingWithErrrCode:faildCode url:url];
                }
                [subscriber sendError:newError];
            }];
            return nil;
        }];
    }];
}

+ (void)errorHandlingWithErrrCode:(NSInteger)errorcode url:(NSString *)url{
    if (errorcode == 401 || errorcode == 40103) {
        BDUserModel *user = [BDUserModel getCurrentUser];
        if (user.is_guest == YES || user == nil) {
            [BDUserModel getUserIfOverdueAfterBlock:nil];
        }else{
            UIView *view = [UIApplication sharedApplication].keyWindow;
            [view alertWithTitle:ASLocalizedString(@"提示")message:ASLocalizedString(@"需要重新登录")type:AlertTypeAlert cancleTitle:ASLocalizedString(@"确定")otherTitle:nil clickBlock:^(NSInteger index){
                //需要重新登录
                [BDUserModel loginOut];
            }];
        }
    }
    /*
    else if (errorcode == 40104) {
        //这条需要在登录时单独进行判断
//        [[NSNotificationCenter defaultCenter] postNotificationName:@"pushToRegist" object:nil];
    }else{
        NSString *alertStr = nil;
        if (errorcode == 10001) {
            alertStr = ASLocalizedString(@"参数缺失");
        }else if (errorcode == 10002) {
            alertStr = ASLocalizedString(@"参数格式不符");
        }else if (errorcode == 10003) {
            alertStr = ASLocalizedString(@"文件类型不符");
        }else if (errorcode == 10004) {
            alertStr = ASLocalizedString(@"昵称有误，太长或者重复");
        }else if (errorcode == 10005) {
            alertStr = ASLocalizedString(@"日期格式不符");
        }else if (errorcode == 10006) {
            alertStr = ASLocalizedString(@"昵称有误，太长或者重复");
        }else if (errorcode == 10007) {
            alertStr = ASLocalizedString(@"该手机号已被注册");
        }else if (errorcode == 10008) {
            alertStr = ASLocalizedString(@"密码必须6位");
        }else if (errorcode == 10009) {
            alertStr = ASLocalizedString(@"两次密码不一致");
        }else if (errorcode == 10010) {
            alertStr = ASLocalizedString(@"该手机号已被注册");
        }else if (errorcode == 40000) {
            alertStr = ASLocalizedString(@"请求错误");
        }else if (errorcode == 40001) {
            alertStr = ASLocalizedString(@"业务逻辑不合规");
        }else if (errorcode == 40002) {
            alertStr = ASLocalizedString(@"验证码错误或者无效");
        }else if (errorcode == 40003) {
            alertStr = ASLocalizedString(@"保存文件失败");
        }else if (errorcode == 40101) {
            alertStr = ASLocalizedString(@"无权限进行该操作");
        }else if (errorcode == 40102) {
            alertStr = ASLocalizedString(@"登录失败，可能是密码、验证码错误，或者第三方授权失败");
        }else if (errorcode == 40301) {
            alertStr = ASLocalizedString(@"用户被禁用");
        }else if (errorcode == 40302) {
            alertStr = ASLocalizedString(@"该账号已注册");
        }else if (errorcode == 50000) {
            alertStr = ASLocalizedString(@"服务器错误");
        }else{
            alertStr = ASLocalizedString(@"网络不好，请检查网络");
        }
        if (alertStr != nil) {
            [MBManager hideAlert];
            UIView *view = [UIApplication sharedApplication].keyWindow;
            [view alertWithTitle:ASLocalizedString(@"提示")message:alertStr type:AlertTypeAlert cancleTitle:ASLocalizedString(@"确定")otherTitle:nil clickBlock:nil];
//            [MBManager showPermanentAlert:alertStr clickHidden:YES clickBlock:nil];
        }
    }*/
}

@end
